<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.User"%>

<script type="text/javascript">

$(document).ready(function() {	
	$("#cancelEditGroupBtn").click(function() {
		$("#editCommissionCodeTableDiv").dialog("close");
	});

	//
	$("#doSaveGroupBtn").click(function() {
		var groupPk = $('#editGroup\\.groupPk').val();
		var chainstoreAmount = $('#editGroup\\.chainstoreAmount').val();
		var postAmount = $('#editGroup\\.postAmount').val();
		var atmAmount = $('#editGroup\\.atmAmount').val();
		var bankAmount = $('#editGroup\\.bankAmount').val();
		var remittanceAmount = $('#editGroup\\.remittanceAmount').val();
		var otherAmount = $('#editGroup\\.otherAmount').val();
		var selfAmount = $('#editGroup\\.selfAmount').val();
		var errMsg = "";
		if (null == chainstoreAmount || 0 == chainstoreAmount.length){
			errMsg = errMsg + "超商是必要欄位<br/>";
		}else if (isNaN(chainstoreAmount)){
			errMsg = errMsg + "超商格式錯誤<br/>";
		}
		if (null == postAmount || 0 == postAmount.length){
			errMsg = errMsg + "郵局是必要欄位<br/>";
		}else if (isNaN(postAmount)){
			errMsg = errMsg + "郵局格式錯誤<br/>";
		}
		if (null == atmAmount || 0 == atmAmount.length){
			errMsg = errMsg + "ATM/IB是必要欄位<br/>";
		}else if (isNaN(atmAmount)){
			errMsg = errMsg + "ATM/IB格式錯誤<br/>";
		}
		if (null == bankAmount || 0 == bankAmount.length){
			errMsg = errMsg + "臨櫃是必要欄位<br/>";
		}else if (isNaN(bankAmount)){
			errMsg = errMsg + "臨櫃格式錯誤<br/>";
		}
		if (null == remittanceAmount || 0 == remittanceAmount.length){
			errMsg = errMsg + "匯款是必要欄位<br/>";
		}else if (isNaN(remittanceAmount)){
			errMsg = errMsg + "匯款格式錯誤<br/>";
		}
		if (null == otherAmount || 0 == otherAmount.length){
			errMsg = errMsg + "授權扣款（ＡＣＨ）是必要欄位<br/>";
		}else if (isNaN(otherAmount)){
			errMsg = errMsg + "授權扣款（ＡＣＨ）格式錯誤<br/>";
		}
		if (null == selfAmount || 0 == selfAmount.length){
			errMsg = errMsg + "自行繳款是必要欄位<br/>";
		}else if (isNaN(selfAmount)){
			errMsg = errMsg + "自行繳款格式錯誤<br/>";
		}
		if (0 != errMsg.length){
			$("#ajaxErrorMessageDiv").html(errMsg);
			$("#ajaxErrorMessageDiv" ).dialog({  
				title:'請修正下列錯誤' 
				,width: 300
				, resizable: false
				, modal: true
				, buttons: {
					Ok: function() {
						$( this ).dialog( "close" );
					}
				}
			});
			return false;
		}
		$('#hidden\\.editGroup\\.groupPk').val(groupPk);
		$('#hidden\\.editGroup\\.chainstoreAmount').val(chainstoreAmount);
		$('#hidden\\.editGroup\\.postAmount').val(postAmount);
		$('#hidden\\.editGroup\\.bankAmount').val(bankAmount);
		$('#hidden\\.editGroup\\.atmAmount').val(atmAmount);
		$('#hidden\\.editGroup\\.remittanceAmount').val(remittanceAmount);
		$('#hidden\\.editGroup\\.otherAmount').val(otherAmount);
		$('#hidden\\.editGroup\\.selfAmount').val(selfAmount);
		doSaveGroupApp();
	});
	function doAjaxSaveGroup() {
		$('#doAjaxMethod').attr('name', 'doAjaxSaveGroup');
		
		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9008.action'/>",
			async : true,
			type : 'POST',
			data : 	$("#editGroupHiddenForm").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {
				$("#ajaxErrorMessageDiv").html(data);
				$("#ajaxErrorMessageDiv").dialog({
					title : '<%=UserUtil.getCurrentMenuItemName() %>',
					width : 300,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
							
							if (1==$("#doAjaxSaveGroupResultCode").val()){
								
								
								if (1==$("#continueEditRealAccount").val()){
									var pk = $("#doAjaxSavegroupPk").val();
									$('#editGroup\\.groupPk').val(pk);
									$('#hidden\\.editGroup\\.groupPk').val(pk);
									$("#editRealAccountBtn").show();
									doQueryAction();
								}
								else{
									$("#editGroupDiv").dialog("close");
									doQueryAction();
								}
								
								
								
							}
						}
					}
				});
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
			}
		});
	}
});
</script>
<div id="editGroupFormDiv">
	<stripes:form id="editGroupForm" name="editGroupForm" 
		beanclass="com.feib.soeasy.action.Soez9008ActionBean" method="post" onsubmit="javascript: return false;">
		<table id="listTable" class="realAccountList">
		<thead>
			<tr>
				<th align="center">收費方式</th>
				<th align="center">帳務處理費</th>
				<th align="center">超商</th>
				<th align="center">郵局</th>
				<th align="center">ATM/IB</th>
				<th align="center">臨櫃</th>
				<th align="center">匯款</th>
				<th align="center">授權扣款<br>（ＡＣＨ）</th>
				<th align="center">自行繳款</th>
			</tr>
			<tr><stripes:hidden id="editGroup.groupPk" name="editGroup.groupPk" />
			<td align="center">按筆數
			</td>
			<td align="center">元/筆
			</td>
			<td align="center"><stripes:text id="editGroup.chainstoreAmount" name="editGroup.chainstoreAmount" size="1" maxlength="2"/>
			</td>
			<td align="center"><stripes:text id="editGroup.postAmount" name="editGroup.postAmount" size="1" maxlength="2"/>
			</td>
			<td align="center"><stripes:text id="editGroup.atmAmount" name="editGroup.atmAmount" size="1" maxlength="2"/>
			</td>
			<td align="center"><stripes:text id="editGroup.bankAmount" name="editGroup.bankAmount" size="1" maxlength="2"/>
			</td>
			<td align="center"><stripes:text id="editGroup.remittanceAmount" name="editGroup.remittanceAmount" size="1" maxlength="2"/>
			</td>
			<td align="center"><stripes:text id="editGroup.otherAmount" name="editGroup.otherAmount" size="1" maxlength="2"/>
			</td>
			</td>
			<td align="center"><stripes:text id="editGroup.selfAmount" name="editGroup.selfAmount" size="1" maxlength="2"/>
			</td>
			</tr>
			<tr>
			<td colspan="8" class="queryFunction" align="center">
				<input type="button" id="doSaveGroupBtn" value="確認" />
				<input type="button" value="離開" id="cancelEditGroupBtn"/>
			</td>
			</tr>	
		</thead>
		</table>
		</stripes:form>
</div>

<div id="editGroupHiddenDiv" style="display: none;">
<stripes:form id="editGroupHiddenForm" name="editGroupHiddenForm" 
	beanclass="com.feib.soeasy.action.Soez9008ActionBean" method="post" onsubmit="javascript: return false;">
	<input id="hidden.editGroup.groupPk" name="editGroup.groupPk" />
	<input id="hidden.editGroup.chainstoreAmount" name="editGroup.chainstoreAmount" />
	<input id="hidden.editGroup.postAmount" name="editGroup.postAmount" />
	<input id="hidden.editGroup.atmAmount" name="editGroup.atmAmount" />
	<input id="hidden.editGroup.bankAmount" name="editGroup.bankAmount" />
	<input id="hidden.editGroup.remittanceAmount" name="editGroup.remittanceAmount" />
	<input id="hidden.editGroup.otherAmount" name="editGroup.otherAmount" />
	<input id="hidden.editGroup.selfAmount" name="editGroup.selfAmount" />
	<input type="hidden" id="doAjaxMethod" name="doAjaxSaveGroup" />
</stripes:form>
</div>

